package io.bluerain.asnycimage.ui;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.Toast;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import io.bluerain.asnycimage.R;

/**
 * Created by foredawn on 15-10-2.
 * 异步加载图片基本示例
 */
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.imageview_simple);
        //初始化操作
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
                .build();
        ImageLoader.getInstance().init(config);

        //获取Loader实例
        ImageLoader loader = ImageLoader.getInstance();

        ImageView imageView = (ImageView) findViewById(R.id.img_view);

        String imgUrl = "http://cn.bing.com/az/hprichbg/rb/CarinaNebula_ZH-CN11667585319_1920x1080.jpg";
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.loading) //图片下载时显示的内容
                .build();

        //加载一张网络中的图片
        loader.displayImage(imgUrl, imageView, options);

        Toast.makeText(this, "即将呈现网络图片", Toast.LENGTH_LONG).show();

    }
}
